﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Test.Model;

namespace Test.DAL
{
    public class StuInfoDAL:BaseDAL<StuInfo>
    {
        

        //public static DataTable Select(string name = "")
        //{
        //    var sql = $"select * from StuInfo where name like '%{name}%'";
        //    return DBHelper.Query(sql);
        //}

        public List<StuInfo> Select(string name = "")
        {

            return Select(p => p.Name.Contains(name));
        }



        //public static int Delete(int id)
        //{
        //    var sql = $"delete from StuInfo where id={id}";
        //    return DBHelper.NonQuery(sql);
        //}

        //public StuInfo Select(int id)
        //{

        //    //model.StuInfoes.FirstOrDefault(p => p.Id == id)
        //    return Model.StuInfoes.Find(id);//FirstOrDefault LastOrDefault

        //}
        

        public int Update(StuInfo info)
        {

            var cls = Model.StuInfoes.Find(info.Id);
            if (cls != null)
            {
                cls.Name = info.Name;
                cls.Comment = info.Comment;
                cls.Cid = info.Cid;
            }
            return Model.SaveChanges();
        }
    }
}
